﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DepartmentSystem
{
    public partial class DepartmentAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            string deptName = TextBox1.Text;
            string headNum = TextBox2.Text;
            string startTime = "";

            if (deptName.Length == 0)
            {
                Response.Write("<script>alert('部门号不能为空！')</script>");
                return;
            }
            if(headNum.Length != 0)
            {
                DateTime dt = DateTime.Now;

                startTime = dt.ToString();
            }
            string sql = "insert into tb_department (deptName, headNum, startTime) values('" + deptName + "', '" + headNum + "', '" + startTime + "')";

            if (SQLHelper.executeNoQuery(sql) != 1)
            {
                Response.Write("<script>alert('添加失败!')</script>");
            }
            else
            {
                Response.Write("<script>alert('添加成功!')</script>");
                Server.Transfer("DepartmentInfo.aspx");

            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

            Server.Transfer("DepartmentInfo.aspx");
        }
    }
}